home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
271_02
/
gameport.doc
< prev
next >
Wrap
Text File
|
1987-08-14
|
3KB
|
76 lines
NAME
gameport functions -- manipulate game port
SYNOPSIS
(void)init_game(mode); initialize and set mode
(void)clear_game(); clear pending input
r = get_press(); get waiting keypress
(void)debounce(); input debouncer
int mode; single/multi stroke mode
unsigned char r; key value
DESCRIPTION
This series of functions is used to read and debounce the
four switch inputs on the joystick input port. The
analog joystick inputs are not supported.
init_game() is called to setup the processor. If its
argument is TRUE, then multiple key inputs are allowed.
If FALSE, any multiple key closure will be locked out.
debounce() must be called periodically in order to
debounce and process the switch inputs. It is suggested
that debounce() be called about 75 to 100 times per second.
The structure "gamesw" contains information used by
these routines. The number of times debounce must be invoked
to return a valid input is contained in gamesw.seed, and may
be altered as desired.
get_press() is called to return any fully debounced input.
A value of 0 indicates no input available.
Calling clear_game() clears any pending input and forces
the debouncer to assume a new input sequence.
The game port was originally intended for playing games via
an arcade-style joystick. However, for the serious engineer,
this port is an excellent "quick and dirty" 4 bit TTL level
input port. It may be used for reading external switches,
sensors, etc.
Switch values are returned as an 8 bit value, with only the
lowest 4 bits in use. A set bit indicates a closed switch.
If multiple keystrokes are not allowed, then get_press() will
return 0, 1, 2, 4, or 8. If multiples are allowed, then
all values 0-15 (0-0x0f) may be returned.
bit position pin number on connector
0 2
1 7
2 14
3 10
gameport functions page 2
EXAMPLE
main() {
unsigned char i;
init_game(FALSE); /* allow only single switch inputs */
for ever() {
debounce(); /* call this regularly */
i = get_press();
if(i is 0) continue;
printf("switch value is %x\n", i);
}
}
This function is found in SMTCx.LIB for the Turbo C Compiler